﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ShopManagement.Dao;
using ShopManagement.Common;
using ShopManagement.Forms;

namespace ShopManagement
{
    public partial class LoginForm : Form
    {
        private SmDao _myDao;
        public LoginForm(SmDao myDao)
        {
            _myDao = myDao;
            InitializeComponent();
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {

        }

        private void btLogin_Click(object sender, EventArgs e)
        {
            string acc = txtAccount.Text.Trim();
            string pass = txtPassword.Text.Trim();
            bool status = _myDao.ValidateAccInfo(acc, pass);
            if(status)
            {
                Visible = false;
                int role = _myDao.GetAccountRole(acc);
                
                MainForm myForm = new MainForm(_myDao,role);
                myForm.ShowDialog();
                Close();
            }
            else
            {
                MessageBox.Show(Constants.Messages.WrongAccPass,"",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
        }

        private void btExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
            _myDao.CloseConnection();
        }



    }
}
